<?php
// +----------------------------------------------------------------------
// | OneThink [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.onethink.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: 麦当苗儿 <zuojiazi@vip.qq.com> <http://www.zjzit.cn>
// +----------------------------------------------------------------------

namespace Home\Controller;
use User\Api\UserApi;
use Think\Page;

/**
 * 后台用户控制器
 * @author 麦当苗儿 <zuojiazi@vip.qq.com>
 */
class PoliceController extends HomeController {

    /**
     * 用户管理首页
     * @author 麦当苗儿 <zuojiazi@vip.qq.com>
     */
    public function index(){

        header("Content-type: text/html; charset=utf-8");

        $infoModel = D('information_type');
        $infoDate  = D('information_view');

        //导航栏
        $this->typeList = M('information_type')->where('status = 1')->select();

        //
        $con1['tid'] = 14;
        $con1['status'] = 1;
        $this->fristType = $infoDate->where($con1)->order('id desc')->find();

        //
        $con2['tid'] = array('eq',14);
        $con2['status'] = array('eq',1);
        $con2['id'] = array('lt',$this->fristType['id']);
        $this->twoType   = $infoDate->where($con2)->order('id desc')->limit(4)->select();

        //
        $con3['tid'] = array('eq',15);
        $con3['status'] = array('eq',1);
        $this->threeType = $infoDate->where($con3)->order('id desc')->limit(5)->select();

        //
        $con4['tid'] = array('eq',16);
        $con4['status'] = array('eq',1);
        $this->fourType  = $infoDate->where($con4)->order('id desc')->limit(5)->select();

        //
        $con5['tid'] = array('eq',17);
        $con5['status'] = array('eq',1);
        $this->fiveType  = $infoDate->where($con5)->order('id desc')->limit(1)->find();

        //
        $con6['tid'] = array('eq',17);
        $con6['status'] = array('eq',1);
        $con6['id'] = array('lt',$this->fiveType['id']);
        $this->sixType  = $infoDate->where($con6)->order('id desc')->limit(3)->select();

        //
        $con7['tid'] = array('eq',18);
        $con7['status'] = array('eq',1);
        $this->sevenType  = $infoDate->where($con7)->order('id desc')->limit(1)->find();

        //
        $con8['tid'] = array('eq',18);
        $con8['status'] = array('eq',1);
        $con8['id'] = array('lt',$this->sevenType['id']);
        $this->eightType  = $infoDate->where($con8)->order('id desc')->limit(3)->select();

        //
        $con9['tid'] = array('eq',19);
        $con9['status'] = array('eq',1);
        $this->nineType  = $infoDate->where('tid = 19')->order('id desc')->limit(1)->find();

        //
        $con10['tid'] = array('eq',19);
        $con10['status'] = array('eq',1);
        $con10['id'] = array('lt',$this->nineType['id']);
        $this->tenType  = $infoDate->where($con10)->order('id desc')->limit(3)->select();

        //
        $con11['tid'] = array('eq',20);
        $con11['status'] = array('eq',1);
        $this->elevenType  = $infoDate->where('tid = 20')->order('id desc')->limit(1)->find();

        //
        $con12['tid'] = array('eq',20);
        $con12['status'] = array('eq',1);
        $con12['id'] = array('lt',$this->elevenType['id']);
        $this->twelveType  = $infoDate->where($con12)->order('id desc')->limit(3)->select();

        //
        $con13['tid'] = array('eq',23);
        $con13['status'] = array('eq',1);
        $this->thirteenType  = $infoDate->where($con13)->order('id desc')->limit(1)->find();

        //
        $con14['tid'] = array('eq',23);
        $con14['status'] = array('eq',1);
        $con14['id'] = array('lt',$this->thirteenType['id']);
        $this->fourteenlveType  = $infoDate->where($con14)->order('id desc')->limit(3)->select();
        //dump( $this->twelveType);
        //----------------------------------------------------------------------------------------------------------------
        //作者：韩金浩
        //典型案例
        $alcon['tid'] = 23;
        $this->anliList =$infoDate->where($alcon)->order('id desc')->limit(3)->field('tupian')->select();
        //荣誉室
        $rcon['tid'] = 24;
        $this->rongyushi =$infoDate->where($rcon)->order('id desc')->getField('tupian');
        //分局排名
        //上报量
        $ucon['group_id'] = 2;
        $this->unit = $infoDate->where($ucon)->group('uid')->getField('uid,nickname,count(uid),sum(click)',true);
        $ucon['status'] = 1;
        $allow = $infoDate->where($ucon)->group('uid')->getField('uid,count(uid)',true);
        foreach ($unit as $key => $value) {
            $this->unit[$key]['allow'] = $allow[$key]['count(uid)'];
        }
        //----------------------------------------------------------------------------------------------------------------
        $this->display();
    }
    public function login($username = '', $password = ''){

    header("Content-type: text/html; charset=utf-8");

    if(IS_POST){ //登录验证

        /* 调用UC登录接口登录 */
        $user = D('member_view');
        $data['username'] = I('username');
        $data['password'] = md5(sha1("admin") . ';H8%Vizh-wBcu|"F}?$t~!=@30bOn`G#&ZP(/7Qg');
        $uid = $user->where($data)->find();
        $arr = explode(',',I('Notice'));
        
        if(in_array($uid['areaid'],$arr)){
        //if($uid['areaid']==I('Notice')){ 
            /* 登录用户 */
            $data1['uid'] = $uid['uid'];
            $data1['nid'] = I('nid');
            //$data1['ctime'] = time();
            $data2 = M('journal')->where($data1)->select();
            if(!$data2){
                M('journal')->add($data1);
                echo "<script>";
                echo "alert('签到成功');";
                echo "history.go(-1);";
                echo "</script>";
                exit;
            }else{
                echo "<script>";
                echo "alert('你已经签到了');";
                echo "history.go(-1);";
                echo "</script>";
                exit;
            }

        } else { 
            echo "<script>";
            echo "alert('公告信息与您所在地区不符');";
            echo "history.go(-1);";
            echo "</script>";
            exit;
        }

    } else { //显示登录表单
        $this->display();
    }
}
    public function listType()
    {
        header("Content-type:text/html;charset=utf-8");
        $infoModel = D('information_type');
        $infoDate  = D('information_view');
        $con['tid'] = I('tid');
        $con['status'] = array('eq',1);

        //列表轮播图
        $this->listLunBo = $infoDate->where($con)->order('id desc')->limit(4)->select();
        //最新或者置顶
        $this->zuiXin = $infoDate->where($con)->order('id desc')->find();

        //内容
        $count = $infoDate->where($con)->count();//查询总记录数
        $Page = new Page($count,10);// 实例化分页类 传入总记录数和每页显示的记录数
        $show = $Page->show();// 分页显示输出
        $this->typeContent = $infoDate->where($con)->limit($Page->firstRow.','.$Page->listRows)->select();
        //导航栏
        $this->typeList = M('information_type')->where('status = 1')->select();

        $this->assign('_page', $show);
        $this->display(); 
    }


    public function xq()
    {

        /*$this->Previous上一篇   $this->Next上一篇*/
        header("Content-type: text/html; charset=utf-8");

        $infoData = D('information');
        $infoDate  = D('information_view');
        $infoModel = D('information_type');

        //导航栏
        $this->typeList = M('information_type')->where('status = 1')->select();

        //公告
        $Notice = M('notice')->find();
        $area_id = explode(',',$Notice['area_id']);
        foreach ($area_id as $key => $value) {
            $area_ID[] = M('area')->where('areaID = '.$value)->getField('area');
        }
        $this->assign('Notice',$Notice);
        $this->assign('area_ID',$area_ID);
        //dump($Notice);
        // dump($area_ID);exit;

        $con['id'] = I('id');
        $con['status'] = array('eq',1);
        $this->xqType = $infoDate->where($con)->find();
        $data['click'] = $this->xqType['click']+1;
        $infoData->where($con)->save($data);
        $this->click = $infoData->where($con)->find();

        //上一篇
        $con1['status'] = array('eq',1);
        $con1['tid'] = array('eq',$this->xqType['tid']);
        $con1['id'] = array('lt',$this->xqType['id']);
        $this->Previous = $infoDate->where($con1)->find();

        //下一篇
        $con2['status'] = array('eq',1);
        $con2['tid'] = array('eq',$this->xqType['tid']);
        $con2['id'] = array('gt',$this->xqType['id']);
        $this->Next = $infoDate->where($con2)->find();
        $this->display();
        
    }

}
